'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-11-06 14:43:35
'''
#
# @lc app=leetcode.cn id=1525 lang=python3
#
# [1525] 字符串的好分割数目
#

# @lc code=start
class Solution:
    def numSplits(self, s: str) -> int:
        tmp = set()
        pref = [0]*len(s)
        suf = [0]*len(s)
        ans = 0
        for i in range(len(s)):
            tmp.add(s[i])
            pref[i] = len(tmp)
        tmp = set()
        for i in range(len(s)-1, -1, -1):
            tmp.add(s[i])
            suf[i] = len(tmp)
        for i in range(len(s)-1):
            if pref[i] == suf[i+1]:
                ans+=1
            if pref[i]>suf[i-1]:
                break
        return ans
# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    s = "aacaba"
    print(solution.numSplits(s))